function getAjaxObj(){
	var xmlhttp;
 if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
	  xmlhttp=new XMLHttpRequest();
	}else{// code for IE6, IE5
	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
	return xmlhttp;
}
var methodGetAjax=getAjaxObj();
var methodPostAjax=getAjaxObj();


function deleteFolder(id){
	var url='/index.php/Home/Folder/deleteFolder/folderId/'+id;
	methodGetAjax.onreadystatechange=callbalk;
	methodGetAjax.open('GET',url,true);
	methodGetAjax.send();
	
    function callbalk(){
      if(methodGetAjax.readyState==4 && methodGetAjax.status==200){
	   console.log(methodGetAjax.responseText);
	   var statuObj=JSON.parse(methodGetAjax.responseText);
	   if(statuObj.status===false){
		 alert('删除失败');
         return false;		 
	   }
	   var node=document.getElementById('folderID_'+id);
	   node.parentNode.removeChild(node);
      }
     }
}

function  renameFolderName(folderID){
	var folderName=prompt('请输入新的收藏夹名字')
	if(folderName== null){
		return false;
	}
	var url='/index.php/Home/Folder/renamefolderName/folderId/'+folderID;
	methodPostAjax.onreadystatechange=callbalk;
	methodPostAjax.open("POST",url,true);
	methodPostAjax.setRequestHeader("Content-type","application/x-www-form-urlencoded");
	methodPostAjax.send("folder_name="+folderName);
    function callbalk(){
      if(methodPostAjax.readyState==4 && methodPostAjax.status==200){
	   console.log(methodPostAjax.responseText);
	   var statuObj=JSON.parse(methodPostAjax.responseText);
	   if(statuObj.status==false){
		 alert('重命名失败');
         return false;		 
	   }
	   var node=document.getElementById('folderID_'+folderID);
	   alert('ok');
      }
     }	
}


 
function addSite(){
	var siteAddres=document.getElementById('siteDialogURL').value;
	var siteName=document.getElementById('siteDialogName').value;
	var siteAccount=document.getElementById('siteDialogUsername').value;
	var sitePassword=document.getElementById('siteDialogPassword').value;
	var folderId=document.getElementById('siteDialogGroup').value;
	var remark=document.getElementById('siteDialogNotes').value;
	if(siteAddres==''){
		alert('网站地址不能为空');
		return false;
	}
	if(siteName==''){
		alert('网站名字不能为空');
		return false;
	}
	if(siteAccount==''){
		alert('网站账号不能为空');
		return false;
	}
	if(sitePassword==''){
		alert('网站密码不能为空');
		return false;
	}



	
	var url='http://127.0.0.1/index.php/Home/SiteInfo/addSite';
	methodPostAjax.onreadystatechange=callbalk;
	methodPostAjax.open("POST",url,true);
	methodPostAjax.setRequestHeader("Content-type","application/x-www-form-urlencoded");
	methodPostAjax.send("site_name="+siteName+"&site_addres="+siteAddres+"&site_account="+siteAccount+"&site_password="+sitePassword+"&folder_id="+folderId+"&remark="+remark);
	 function callbalk(){
      if(methodPostAjax.readyState==4 && methodPostAjax.status==200){
	   console.log(methodPostAjax.responseText);
	   var statuObj=JSON.parse(methodPostAjax.responseText);
	   if(statuObj.status==false){
		 alert('添加失败');
         return false;		 
	   }
	   alert('ok');
	   
      }
     }	
	
}

